export interface CompanyProp {
    code: string; // 公司证券代码

    name: string; // 公司名称

    percentage?: number; // 仓位占比

    price?: number; // 当前价格

    shares?: number; // 当前持仓股数

    marketValue?: number; // 总市值(亿)

    startPrice?: number; // 年初复权价格

    increase?: number; // 年内涨幅

    buyValue?: number; // 年内买点(亿)

    sellValue?: number; // 年内卖点(亿)

    estimatedValue?: number; // 三年后估值(亿)

    remark?: string; // 估值备注
}

export class Company implements CompanyProp {
    code = '';

    name = '';

    percentage?: number;

    price?: number;

    shares?: number;

    marketValue?: number;

    startPrice?: number;

    increase?: number;

    buyValue?: number;

    sellValue?: number;

    estimatedValue?: number;

    remark?: string;

    constructor(company: CompanyProp) {
        this.code = company.code;
        this.name = company.name;
        this.percentage = company.percentage;
        this.price = company.price;
        this.shares = company.shares;
        this.marketValue = company.marketValue;
        this.startPrice = company.startPrice;
        this.increase = company.increase;
        this.buyValue = company.buyValue;
        this.sellValue = company.sellValue;
        this.estimatedValue = company.estimatedValue;
        this.remark = company.remark;
    }

    useExchangeRate() {
        return this.code.startsWith('hk');
    }

    exportMarkdownRow() {
        return `| ${this.percentage?.toFixed(2)}% | ${this.name} | ${this.marketValue?.toFixed(0) ?? ' '} | `
         + `${this.buyValue ?? ' '} | ${this.sellValue ?? ' '} | ${this.estimatedValue ?? ' '} | `
         + `${this.increase?.toFixed(2) ?? ' '}% |`;
    }
}
